﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OnlineFamilyCalendar.Model
{
    public class FamilyMember : IValidate
    {
        public Guid FamilyMemberId { get; set; }
        public string FirstName { get; set; }
        public string EmailAddress { get; set; }
        public LoginInformation LoginInformation { get; set; }
        private int RoleDefinition { get; set; }

        internal FamilyMember()
        {
        }

        public static FamilyMember Create(LoginInformation loginInformation)
        {
            FamilyMember familyMember = new FamilyMember
            {
                FamilyMemberId= Guid.NewGuid(),
                FirstName = String.Empty,
                EmailAddress = String.Empty,
                LoginInformation = loginInformation,
                Role = Role.None
            };

            return familyMember;
        }

        public Role Role
        {
            get { return (Role)RoleDefinition; }
            set { RoleDefinition = (int)value; }
        }

        public string RoleName
        {
            get
            {
                return Enum.GetName(typeof(Role), this.Role);
            }
        }

        public void Validate(ChangeAction action)
        {
            if (action == ChangeAction.Insert || action == ChangeAction.Update)
            {
                if (FamilyMemberId == Guid.Empty)
                    throw new InvalidOperationException("FamilyMemberId can not be empty");
            }
        }
    }
}
